<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ExtendedJuiDialog
 *
 * @author Chris Sim
 */

Yii::import('zii.widgets.jui.CJuiDialog');

class ExtendedJuiDialog extends CJuiDialog {
    //put your code here

    public $content = null;

    public $ajaxURL = null;

    public $triggerbutton = null;

    public function run() {
        $id = $this->getId();
        $function = (!is_null($this->ajaxURL))?"$('#{$id}').load('{$this->ajaxURL}','',function(responseText, textStatus, XMLHttpRequest){if(textStatus == 'success'){ $('#{$id}').dialog('open');}});":"$('#{$id}').dialog('open');";
        if(is_null($this->ajaxURL) && !is_null($this->content))
            echo $this->content;
        if($this->triggerbutton === null) {
        $script =<<<EOP
function {$id}_open() {
{$function}
}
EOP;
        $scriptPOS = CClientScript::POS_END;
        }
        else {
            $script =<<<EOP
$("{$this->triggerbutton}").bind("click",function(){{$function}});
EOP;
            $scriptPOS = CClientScript::POS_READY;
        }
        Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,$script,$scriptPOS);
        echo CHtml::closeTag($this->tagName);
    }
}
?>
